import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class MovieRepository {
    private static Map<String, Movie> movies = new HashMap<>();
    private static Map<String, String> titleToId = new HashMap<>();

    public static boolean addMovie(Movie movie) {
        if (movies.containsKey(movie.getMovieId()) || titleToId.containsKey(movie.getTitle())) {
            return false;
        }
        movies.put(movie.getMovieId(), movie);
        titleToId.put(movie.getTitle(), movie.getMovieId());
        return true;
    }
    public static Movie getMovieById(String movieId) {
        return movies.get(movieId);
    }
    public static Movie getMovieByTitle(String title) {
        String movieId = titleToId.get(title);
        return movieId != null ? movies.get(movieId) : null;
    }
    public static boolean removeMovie(String movieId) {
        Movie movie = movies.get(movieId);
        if (movie != null) {
            movies.remove(movieId);
            titleToId.remove(movie.getTitle());
            return true;
        }
        return false;
    }
    public static List<Movie> getAllMovies() {
        return new ArrayList<>(movies.values());
    }
}